tic;
%[]Starts program timer.

clc;
%[]Clears command window.

clear;
%[]Clears variable workspace.

format('LongG');
%[]Adjusts the format of the command window output.

format('Compact');
%[]Adjusts the format of the command window output.

close('All');
%[]Closes all windows.

%%
%[]CONSTANTS AND GIVEN QUANTITIES:

UTC = [2018, 2, 2, 0, 0, 0];
%[year,month,day,hour,minute,second]Coordinated universal time at mission commencement.

u = 398600.44;
%[km^3/s^2]Gravitational parameter of the Earth.

%%
%[]INITIAL CONDITIONS NUMERICAL INTEGRATION:

to = [0, 24*36000];
%[s]Simulation time.


Coe = [9909; 0; 99; 0; 0; 0];
%[km,-,deg,deg,deg,deg]Initial satellite classical orbital elements WRT the Earth.

So = Coe2State(Coe,u);
%[] get state information from Coe

options = odeset('RelTol',1e-10);
%[]Adjusts the accuracy of the numerical integrator.

[t,S] = ode45(@(t,S)R2bpCartesianModel(t,S,u),to,So,options);
%[s,km,km/s]Numerically integrates the relative two-body problem equations of motion.

%%
%[]POST PROCESSING:

t = transpose(t);
%[s]Transpose of the time vector.

S = transpose(S);
%[km,km/s]Transpose of the state matrix.

R = S(1:3,:);
%[km]Position vectors WRT the Earth in ECI coordinates during the simulation time.

V = S(4:6,:);
%[km/s]Velocity vectors WRT the Earth in ECi coordinates during the simulation time.

%%
%[]PLOT RESULTS:

PlotOrbit(R);
%[]Plots the orbit in three (3) dimensions.

% pause;
%[]Pauses the code until the spacebar is pressed.

% PlotGroundTrack(t,R,UTC);
%[]Plots the orbit's ground track.

% pause;
%[]Pauses the code until the spacebar is pressed.

% PlotCoe(t,S,u,'Hours','Earth Radii');
%[]Plots the classical orbital elements as a function of time.

% pause;
%[]Pauses the code until the spacebar is pressed.

%%
%[]ANIMATE RESULTS:

% dt = 60 * 1;
% %[s]Animation time step.
% 
% AnimateOrbit(t,R,UTC,dt);
% %[]Animates the orbit in three dimensions.
% 
% pause;
% %[]Pauses the code until the spacebar is pressed.
% 
% AnimateGroundTrack(t,R,UTC,dt);
% %[]Animates the orbit's ground track.

%%
%[]DISPLAY SIMULATION TIME:

SimulationTime = toc;
%[]Stops program timer.

fprintf('Simulation Time: %0.3f seconds\n',SimulationTime);
%[]Displays the simulation time on the command window.
%===================================================================================================